//
//  WhisperTips.swift
//  777Proj
//
//  Created by 陈宇 on 2017/5/17.
//  Copyright © 2017年 🐜. All rights reserved.
//

import Foundation
import Whisper

func configureWhisper() {
    whistleFactory.whistleWindow.windowLevel = UIWindowLevelAlert
}

enum WhisperState {
    case info
    case warn
    case error
    
    func titleColor() -> UIColor {
        switch self {
        case .info:
            return UIColor.white
        case .warn:
            return UIColor(hexString: "#d4410e")
        case .error:
            return UIColor.white
        }
    }
    
    func backgroundColor() -> UIColor {
        switch self {
        case .info:
            return APP.APP_PRIMARY_COLOR
        case .warn:
            return UIColor(hexString: "#fff8ad")
        case .error:
            return UIColor(hexString: "#fb0007")
        }
    }
}

extension UINavigationController {
    
    override func whisper(title: String) {
        Whisper.show(whisper: Whisper.Message(title: title), to: self)
    }
    
}

extension UIViewController {
    
    func whisper(title: String) {
        Whisper.show(shout: Whisper.Announcement(title: title), to: self.navigationController ?? self)
    }
    
}

extension UIApplication {
    class func whisper(title: String, duration: TimeInterval = 5, state: WhisperState = .warn) {
        Whisper.show(whistle: Whisper.Murmur(title: title, backgroundColor: state.backgroundColor(), titleColor: state.titleColor()), action: .show(duration))
    }
}
